package com.firstgroup.repository;

import com.firstgroup.domain.QuessionBank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 题库
 */
public interface QuestionBankRespository extends JpaRepository<QuessionBank,Integer> {


    @Query(value = "select * from quession_bank where type = ?1 limit ?2,?3 ",nativeQuery = true)
    List<QuessionBank> findByQuestionType(String type,Integer start,Integer pageSize);

    /**
     * 自定义查询:根据题库类型进行遍历(面试,笔试)
     */
    List<QuessionBank> findByType(String type);

    Integer deleteById(int id);

    QuessionBank findById(int id);

    @Query("update QuessionBank set quessionName=?2,answer=?4,type=?3 where id=?1")
    @Modifying//update得加这个
    int updateQuession(int id,String quessionName,String answer,String type);

    @Query(value = "select count(*) from QuessionBank where type = ?1")
    Integer queryCountByType(String type);

    //根据问题进行模糊查询 面试
    @Query(value = "select q from QuessionBank q where q.quessionName = ?1")
    List<QuessionBank> findByQuestionNameLike(String name);

    //根据问题进行模糊查询 面试
    @Query(value = "select * from quession_bank  where quession_name like CONCAT('%',?1,'%') and type='面试' limit ?2,?3",nativeQuery = true)
    List<QuessionBank> findByQuestionNameLikeType(String name,Integer start,Integer pageSize);

    //根据问题进行模糊查询 笔试
    @Query(value = "select q from QuessionBank q where q.quessionName like %?1% and q.type='笔试' ")
    List<QuessionBank> findByQuestionNameLikeW(String name);

    //根据问题进行模糊查询 笔试
    @Query(value = "select * from quession_bank  where quession_name like CONCAT('%',?1,'%') and type='笔试' limit ?2,?3",nativeQuery = true )
    List<QuessionBank> findByQuestionNameWType(String name,Integer start,Integer pageSize);







}
